﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<QianBuo.Lottery.Web.Models.Play.PlayTypeModel>" %>
<div >
    <div id="play_inputpanel">
        <table border="0" cellpadding="0" cellspacing="5" class="play_play_input">
            <tr id="input_model">
                <td>
                   &nbsp; 
                </td>
                <td  align="left">
                    <input type="radio" name="inputtype" checked="checked" value="0" id="inputtype_mouse"/><label for="inputtype_mouse">鼠标选择(复式)</label> 
                    <input type="radio" name="inputtype" value="1" id="inputtype_hand"/><label for="inputtype_hand">手工输入(单式)</label>
                </td>
            </tr>
            <tr class="tr_number" id='input_0'>
                <td colspan='2' id="tdNums"></td>
            </tr>
            <tr class="tr_number" id="input_1">
                <td colspan="2" height="120px">
                    <table cellpadding="0" cellspacing="0" border="0" width="100%">
                        <tr>
                            <%if (ViewData["IsTC11X5"] != null && (bool)ViewData["IsTC11X5"]) %>
                            <%{ %>
                                <td align="center">
                                <font color="red" size="-1">每注号码之间可用 换行符 隔开，每注号码每位之间可用 逗号、空格或 ";" 分开。仅支持单式。</font>
                                </td>
                            <%} %>
                            <%else %>
                            <%{ %>
                            <td align="center">
                                <font color="red" size="-1">请在下方的输入框内输入或粘贴投注内容，每注请使用 逗号、空格或 ";" 分割开</font>
                            </td>
                            <%} %>
                        </tr>
                        <tr>
                            <td>
                                <textarea id="input_keybord" class="input_keybord"></textarea>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
             <tr id="playinfo">
                <td colspan="2" style=" text-align:left">
                <%=Model.Remark %>
                </td>
            </tr>
            <tr>
                <td id="sumcount">
                    注数:<font color="red">0</font>
                </td>
                <td align="left">
                    <input type="button" name="bet_play_btnadd" onclick="AddScheme()" id="bet_play_btnadd" value="添加" class="bet_play_btnadd" />
                </td>
            </tr>
        </table>
    
        <script type="text/javascript">
            var __playid=<%=Model.PlayID %>;
            $(document).ready(showWinInfo);
            function showWinInfo(){
                var pwin = Site.Lottery.Bet.GetPlayTypeWinMoney(function(item){ return item.PlayTypeID == __playid;});
                if(pwin != null)
                    $('<span><%=string.IsNullOrEmpty(Model.Remark) ? "" : "，" %>'+"奖金:<font color='red'>"+pwin.WinMoney+"元</font></span>").appendTo($("#playinfo td"));
                else
                    window.setTimeout(showWinInfo,500);
            }
            var playType_obj=<%=ViewData["playType_obj"]??"null" %>;
            if(playType_obj==null){
                window.history.go(-1);
                alert('访问出错!');
            }
            playType_obj.PlayTypeName='<%=Model.Name%>';
            playType_obj.PlayTypeID=<%=Model.ID %>;
            
            Site.Lottery.Bet.SetCurrentPlay(playType_obj.PlayTypeID, playType_obj.PlayTypeName);
            

            var txt=Site.Lottery.Func.GetInputPanel(playType_obj.Names, playType_obj.Min, playType_obj.Max, playType_obj.Flag);
            $("#tdNums").append(txt);

            $(".play_play_input .number").click(function () {
                var item = $(this);
                  var id='';
                  if(item.parent().find("li:first").is('.empty_li')){
                        id=item.parent().parent().find('.head').html();
                  }
                  else{
                        id=item.parent().find('.head').html();
                  }
                if (item.is(".select")) {
                    item.removeClass("select");
                    playType_obj.RemoveChoseNums(id,item.text());
                }
                else {
                    item.addClass("select");
                    playType_obj.AddChoseNums(id,item.text());
                }

                //alert(QianSanZhiXuan.ChooseNumber['p10000'].length+','+QianSanZhiXuan.ChooseNumber['p1000'].length+','+QianSanZhiXuan.ChooseNumber['p100'].length);

                var count = playType_obj.GetNumsCount();

                $(".play_play_input #sumcount font").html(count);
            });

            $(".play_play_input .tool").click(function () {
                SelectNumber(playType_obj,$(this).parent().find(".number"), this.innerText);
            });

            
            function AddScheme() {
                var control = $(".play_play_input #input_1");
                if (control.is(".selectTR")) {
                    var txt = $("#input_keybord");
                    if(playType_obj.IsTC11X5){
                        Site.Lottery.PlayTypes.CheckNumber2(txt.val(), playType_obj);
                    }else{
                        Site.Lottery.PlayTypes.CheckNumber(txt.val(), playType_obj);
                    }
                }
                _AddScheme(playType_obj);
            }

            $("#input_model :radio").each(function () {
                var item = $(this);
                item.click(function () {
                    $(".play_play_input .tr_number").each(function () {$(this).removeClass("selectTR");  $(this).hide(); });
                    var tr = $(".play_play_input #input_" + this.value);
                    tr.show();
                    tr.addClass("selectTR");
                });
                if (item.is(':checked'))
                    item.click();
            });

            if(!playType_obj.HasInputModel){
                $(".play_play_input #input_model").hide();
                $(".play_play_input #input_1").hide();
                $(".play_play_input #input_0").show();
            }
            
 function SelectNumber(obj, numbers, type) {
    numbers.each(function () {
        $(this).removeClass("select");
    });
    obj.ChoseNums[numbers.parent().children()[0].innerText] = '';
    $(".play_play_input #sumcount font").html('0');

    switch (type) {
        case "全":
            numbers.click();
            break;
        case "大":
            numbers.each(function () {
                if (parseInt(this.innerText) > obj.Max/2)
                    $(this).click();
            });
            break;
        case "小":
            numbers.each(function () {
                if (parseInt(this.innerText) < obj.Max/2)
                    $(this).click();
            });
            break;
        case "奇":
            numbers.each(function () {
                if (parseInt(this.innerText) % 2 == 1)
                    $(this).click();
            });
            break;
        case "偶":
            numbers.each(function () {
                if (parseInt(this.innerText) % 2 == 0)
                    $(this).click();
            });
            break;
    }

}

 function _AddScheme(obj) {
    var number = '';
    if (obj.InputNums.length == 0) {
        for (var i = 0; i < obj.Names.length; i++) {
            if(obj.IsTC11X5){
                var list=obj.ChoseNums[obj.Names[i]].split(',');
                if (i == obj.Names.length - 1) {
                    number += list.sort().join(' ');
                    break;
                }
                number+=list.sort().join(' ')+',';
            }
            else if (obj.Max > 9) {
//                number = obj.ChoseNums[obj.Names[i]].split(',').sort().join(',');
                var list=obj.ChoseNums[obj.Names[i]].split(',');
                number+=list.sort().join(',');
            }
            else {
                obj.ChoseNums[obj.Names[i]] = obj.ChoseNums[obj.Names[i]].split('').sort().join('');
                if (i == obj.Names.length - 1) {
                    number += obj.ChoseNums[obj.Names[i]];
                    break;
                }
                number += obj.ChoseNums[obj.Names[i]] + ',';
            }
        }
        var count = obj.GetNumsCount();
        if(count==0){
            alert("选择的号码不正确");
            return ;
        }
        if (Site.Lottery.Bet)
            Site.Lottery.Bet.AddPlayItem(obj.PlayTypeID, obj.PlayTypeName, number, count, 1);
        for (var i = 0; i < obj.Names.length; i++) {
            obj.ChoseNums[obj.Names[i]] = '';
        }
        $(".play_play_input #sumcount font").html('0');
        $(".play_play_input .number").each(function (){
            $(this).removeClass('select');
        });
    } else {
        var items=[];
        for (var i = 0; i < obj.InputNums.length; i++) {
            var newItem={
                playid:obj.PlayTypeID,
                playname:obj.PlayTypeName,
                number:obj.InputNums[i], 
                count:1, 
                args:1
            };
            items=items.concat(newItem);
        }
        if (Site.Lottery.Bet)
            Site.Lottery.Bet.AddPlayItems(items);
        obj.InputNums = [];
        $("#input_keybord").text("");
    }
}
        </script>
    </div>
</div>


